﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BIZModel;
using BL.BIZControls;
using BIZMA._controls.Demo;
namespace BIZMA.Site.Company
{
    public partial class Default : System.Web.UI.Page
    {

        void ContainedListControl_HandledNewItemClick(object sender, Guid objectId, string objectType)
        {
            if (objectType == List_Companies.ListTypeCompany)
            {
                Response.Redirect("Company.aspx?ID=" + objectId.ToString(), true);
            }
        }

        void ContainedListControl_HandledListClick(object sender, Guid objectId, string objectType)
        {
            if (objectType == List_Companies.ListTypeCompany)
            {
                Response.Redirect("Company.aspx?ID=" + objectId.ToString(), true);
            }
        }

        void ContainedListControl_ListSelect(object sender, EventArgs e, bool multipleSelect, List<Guid> selectedItems)
        {
            BIZMAEntities ent = BaseBL.GetEnt();
            lv.DataSource = (from DemoCompany C in ent.DemoCompanies
                             join Guid id in selectedItems on C.CompanyId equals id
                             select new { C.Name });
            lv.DataBind();
        }


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                pcCompany.AddDefaultListLoad(BIZControl.DemoCompanyList);
            }

            if (pcCompany.ContainedListControl != null)
            {
                pcCompany.ContainedListControl.HandledListClick += new BIZListControl.ClickEventHandler(ContainedListControl_HandledListClick);
                pcCompany.ContainedListControl.HandledNewItemClick += new BIZListControl.ClickEventHandler(ContainedListControl_HandledNewItemClick);
                pcCompany.ContainedListControl.ListSelect += new BIZListControl.SelectedChanged(ContainedListControl_ListSelect);
            }

        }

        protected void rbtnSelSingle_CheckedChanged(object sender, EventArgs e)
        {
            pcCompany.ContainedListControl.MultipleSelect = rbtnSelMulti.Checked;
            ((List_Companies)pcCompany.ContainedControl).LoadCompanies();
        }


        protected void chkHandleListEvent_CheckedChanged(object sender, EventArgs e)
        {
            pcCompany.ContainedListControl.HandleListClickEvents = chkHandleListEvent.Checked;
        }
    }
}